package com.liveinstars.activity.application.assembler;

import com.baidu.unbiz.easymapper.MapperFactory;
import com.liveinstars.activity.business.activity.entity.ActivityDO;
import com.liveinstars.activity.business.activity.repository.po.ActivityMembers;
import com.liveinstars.api.dto.ActivityCreateDto;
import com.liveinstars.api.dto.ActivityDetailDto;
import com.liveinstars.api.dto.ActivityDto;
import com.liveinstars.api.dto.ActivityMemberDto;

import java.util.List;
import java.util.stream.Collectors;

public class ActivityAssembler {

    public static ActivityDetailDto toDTO(ActivityDO vo){
        ActivityDetailDto detailDto = MapperFactory.getCopyByRefMapper().mapClass(ActivityDO.class, ActivityDetailDto.class).register()
                .map(vo, ActivityDetailDto.class);
        return detailDto;
    }

    public static ActivityDO toDO(ActivityDto dto) {
        ActivityDO activityDO = MapperFactory.getCopyByRefMapper().mapClass(ActivityDto.class, ActivityDO.class).register()
                .map(dto, ActivityDO.class);
        return activityDO;
    }

    public static List<ActivityDto> toDTOS(List<ActivityDO> list) {
        if(list == null)return null;

        MapperFactory.getCopyByRefMapper().mapClass(ActivityDO.class, ActivityDto.class).register();
        List<ActivityDto> activityDOS = list.stream().map(p -> MapperFactory.getCopyByRefMapper().map(p,
                ActivityDto.class)).collect(Collectors.toList());
        return activityDOS;
    }

    public static List<ActivityMemberDto> toDTO(List<ActivityMembers> list) {
        MapperFactory.getCopyByRefMapper().mapClass(ActivityMembers.class, ActivityMemberDto.class).register();
        List<ActivityMemberDto> activityDOS = list.stream().map(p -> MapperFactory.getCopyByRefMapper().map(p,
                ActivityMemberDto.class)).collect(Collectors.toList());
        return activityDOS;
    }


    public static ActivityMemberDto toDTO(ActivityMembers member) {
        ActivityMemberDto memberDto = MapperFactory.getCopyByRefMapper().mapClass(ActivityMembers.class, ActivityMemberDto.class).register()
                .map(member, ActivityMemberDto.class);
        return memberDto;
    }

    public static ActivityDO toDO(ActivityCreateDto dto) {
        ActivityDO activityDO = MapperFactory.getCopyByRefMapper().mapClass(ActivityCreateDto.class, ActivityDO.class).register()
                .map(dto, ActivityDO.class);
        return activityDO;
    }
}
